<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%--
  Created by IntelliJ IDEA.
  User: lhr
  Date: 2022/5/18
  Time: 20:02
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>

<html>
<head>
    <title>JSTL Foreach 标签</title>
</head>
<body>
    <c:if test="${sessionScope.cars ne null}">
        <table style="width: 100%" border="1">
            <tr style="background-color: blue;color: #fff">
                <th>序号</th><th>产品名称</th><th>产品价格</th><th>产品产品颜色</th>
            </tr>
        <c:forEach items="${sessionScope.cars}" var="car" varStatus="sta">
            <c:if test="${(sta.index+1) mod 2 eq 0}">
            <tr style="background-color: pink">
                <td>${sta.index+1}</td>
                <td>${car.proName}</td>
                <td>${car.price}</td>
                <td>${car.color}</td>
            </tr>
            </c:if>
            <c:if test="${(sta.index+1) mod 2 ne 0}">
                <tr style="background-color: yellow">
                    <td>${sta.index+1}</td>
                    <td>${car.proName}</td>
                    <td>${car.price}</td>
                    <td>${car.color}</td>
                </tr>
            </c:if>
        </c:forEach>
    </c:if>
        </table>
</body>
</html>
